# classe responsavel por validar e ler o XML com o tabuleiro e gerar as classes#
# contidas nele


import lxml.etree
from sys import argv

class ValidationException (lxml.etree.DocumentInvalid):
    pass

class Reader:
    def __init__(self, xmlPath, schemaPath):
	self.xmlPath=xmlPath
	self.schemaPath=schemaPath

    def validate(self):
	xmlSchemaDoc=lxml.etree.parse(self.schemaPath);
	xmlSchema = lxml.etree.XMLSchema(xmlSchemaDoc);
	xmlDoc = lxml.etree.parse(self.xmlPath);
	try:
    	    xmlSchema.assertValid(xmlDoc);
	except lxml.etree.DocumentInvalid as error:
	    raise ValidationException(error)
	
	

if  __name__ == "__main__":
    if ( len(argv) != 3):
        print "usage:\n   XMLValidator [xml file] [xsd file]"
	exit(1)
    reader = Reader(argv[1],argv[2])
    reader.validate()


